package com.kady.Dao.impl;

import com.kady.Dao.FoodTypeDao;
import com.kady.entity.Food;
import com.kady.entity.FoodType;

import java.sql.SQLException;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: kady
 * \* Date: 2021/3/24
 * \* Time: 20:53
 * \* 千峰JAVA2101班
 * \* Description: 菜系Dao
 * \
 */
public class FoodTypeDaoImpl extends BaseDao implements FoodTypeDao {
    /**
     * 查询菜系列表
     */
    @Override
    public List<FoodType> selectFoodTypeList(String keyword) throws SQLException {
        String sql = "SELECT food_type_id typeId,food_type_name typeName FROM food_type WHERE food_type_name LIKE ?;";
        List<FoodType> res = selectListByName(FoodType.class,sql,keyword);
        return res;
    }

    /**
     * 通过菜系ID查询单个菜系
     */
    @Override
    public FoodType selectFoodType(long typeId) throws SQLException {
        String sql = "SELECT food_type_id typeId,food_type_name typeName FROM food_type WHERE food_type_id = ?";
        FoodType foodType = selectOne(FoodType.class,sql,typeId);
        return foodType;
    }

    /**
     * 添加菜系
     */
    @Override
    public void saveFoodType(Object...objs) throws SQLException {
        String sql = "INSERT INTO food_type (food_type_id,food_type_name) VALUES (?,?);";
        update(sql,objs);
    }

    /**
     * 修改菜系
     */
    @Override
    public void updateFoodType(Object...objs) throws SQLException {
        String sql = "update food_type set food_type_name = ? where food_type_id = ?;";
        update(sql,objs);
    }

    /**
     * 删除菜系
     */
    @Override
    public void deleteFoodType(long typeId) throws SQLException {
        String sql = "DELETE FROM food_type WHERE food_type_id = ?";
        update(sql,typeId);
    }

    /**
     * 通过名称寻找对应菜系
     */
    @Override
    public FoodType selectFoodTypeByName(String name) throws SQLException {
        String sql = "SELECT food_type_id typeId,food_type_name typeName FROM food_type WHERE food_type_name = ?";
        FoodType res = selectOne(FoodType.class,sql,name);
        return res;
    }
}
